public class MyCircularQueue {
    int rear;
    int front;
    int size;
    int[] elem;
    int capacity;

    public MyCircularQueue(int k) {
        this.elem = new int[k];
        this.capacity = k;
    }

    public boolean enQueue(int value) {
        if(isFull())
            return false;
        elem[rear] = value;
        rear = (rear==capacity-1)? 0 : rear+1;
        size++;
        return true;
    }

    public boolean deQueue() {
        if(isEmpty())
            return false;
        front = (front==capacity-1) ? 0 : front+1;
        size--;
        return true;
    }

    public int Front() {
        if(isEmpty())
            return -1;
        return elem[front];
    }

    public int Rear() {
        if(isEmpty())
            return -1;
        int ret = rear==0 ? capacity-1 : rear-1;
        return elem[ret];
    }

    public boolean isEmpty() {
        return size==0;
    }

    public boolean isFull() {
        return size==capacity;
    }
}